home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/static/sh # # KNOPPIX General Startup Script # (C) Klaus Knopper <knoppix@knopper.net> # Adapted for the Morphix Base image (www.morphix.org) # by Alex de Landgraaf <alextreme@xs4all.nl> # # # This script needs some of the builtin ash commands (if, test, ...) # mount/umount, insmod/rmmod are also a builtin in ash-knoppix. # # hardcoded configurable options # Default maximum size of dynamic ramdisk in kilobytes RAMSIZE=1000000 # End of options # Don't allow interrupt signals trap "" 1 2 3 15 # "Safe" SCSI modules in the right order for autoprobe # Warning: The sym53c8xx.o and g_NCR* cause a kernel Oops if no such adapter # is present. # # NB: It looks like that ncr53c8xx.o is more stable than 53c7,8xx.o for # a ncr53c810 controller (at least on my installation box it's more # immune to SCSI timeouts) # Removed 53c7,8xx -> crashes if no device attached. # Removed AM53C974 -> crashes tmscsim if adapter found # Added initio.o on request (untested) SCSI_MODULES="aic7xxx.o BusLogic.o \ ncr53c8xx.o NCR53c406a.o \ initio.o \ advansys.o aha1740.o aha1542.o aha152x.o \ atp870u.o dtc.o eata.o fdomain.o gdth.o \ megaraid.o pas16.o pci2220i.o pci2000.o psi240i.o \ qlogicfas.o qlogicfc.o qlogicisp.o \ seagate.o t128.o tmscsim.o u14-34f.o ultrastor.o wd7000.o \ a100u2w.o 3w-xxxx.o" # Misc functions mountit(){ # Usage: mountit src dst "options" # Uses builtin mount of ash.knoppix # Builin filesystems BUILTIN_FS="iso9660 ext2 vfat" for fs in $BUILTIN_FS; do test -b $1 && mount -t $fs $3 $1 $2 >/dev/null 2>&1 && return 0 done return 1 } FOUND_SCSI="" FOUND_MORPHIX="" INTERACTIVE="" # Clean input/output exec >/dev/console </dev/console 2>&1 # Reset fb color mode RESET="]R" # ANSI COLORS # Erase to end of line CRE="" # Clear and reset Screen CLEAR="c" # Normal color NORMAL="" # RED: Failure or error message RED="" # GREEN: Success message GREEN="" # YELLOW: Descriptions YELLOW="" # BLUE: System mesages BLUE="" # MAGENTA: Found devices or drivers MAGENTA="" # CYAN: Questions CYAN="" # BOLD WHITE: Hint WHITE="" # Clear screen with colormode reset # echo "$CLEAR$RESET" # echo "$CLEAR" # Just go to the top of the screen # echo -n "H" echo "" # Be verbose echo "${WHITE}Welcome to the ${YELLOW}MORPHIX${WHITE} liveCD!${NORMAL}" echo "" echo "" # We only need the builtin commands and /static at this point PATH=/static export PATH umask 022 # Mount /proc and /dev/pts mount -t proc none /proc mount -t devpts none /dev/pts # Read boot command line with builtin cat command (shell read function fails in Kernel 2.4.19-rc1) CMDLINE="$(cat /proc/cmdline)" # Check if we are in interactive startup mode case "$CMDLINE" in *BOOT_IMAGE=expert\ *) INTERACTIVE="yes"; :>/interactive; ;; esac # patch from Fabian's linuxrc_modules-disk.diff patch, 2003-07-28 case "$CMDLINE" in *modules-disk*) INTERACTIVE="yes"; ;; esac NOCD="" case "$CMDLINE" in *fromhd*) NOCD="yes"; ;; esac # Does the user want to skip scsi detection? NOSCSI="" case "$CMDLINE" in *noscsi*) NOSCSI="yes"; ;; esac case "$CMDLINE" in *splash*) SPLASH="yes"; ;; esac # Bootsplash by Eadz at eadz.co.nz if test -n "$SPLASH"; then #exec /static/fbresolution splash -s -u 0 /bootsplash/config/bootsplash-1024x768.cfg 2>&1 > /dev/null #/static/splash -s -u 1 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null #/static/splash -s -u 2 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null #/static/splash -s -u 3 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null #/static/splash -s -u 4 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null fi # Do we try to load Base onto ramdisk #case "$CMDLINE" in *basetoram*) BASETORAM="yes"; ;; esac # Disable kernel messages while probing modules in autodetect mode echo "0" > /proc/sys/kernel/printk # Mount module disk mountmodules(){ TYPE="$1"; shift echo -n "${CRE}${CYAN}Please insert ${TYPE} modules disk and hit Return. ${NORMAL}" read a echo -n "${CRE}${BLUE}Mounting ${TYPE} modules disk... ${NORMAL}" # We always mount over /modules/scsi (because it's there ;-) if mountit /dev/fd0 /modules/scsi "-o ro"; then echo "${GREEN}OK.${NORMAL}" return 0 fi echo "${RED}NOT FOUND.${NORMAL}" return 1 } # Unmount module disk umountmodules(){ TYPE="$1"; shift echo -n "${CRE}${BLUE}Unmounting ${TYPE} modules disk... ${NORMAL}" umount /modules/scsi 2>/dev/null echo "${GREEN}DONE.${NORMAL}" } # Ask user for modules askmodules(){ TYPE="$1"; shift echo "${BLUE}${TYPE} modules available:${WHITE}" c=""; for m in "$@"; do if test -f "/modules/scsi/$m"; then test -z "$c" && { echo -n " $m"; c="1"; } || { echo " $m"; c=""; } fi done [ -n "$c" ] && echo "" echo "${CYAN}Load ${TYPE} Modules?${NORMAL}" echo "${CYAN}[Enter full filename(s) (space-separated), Return for autoprobe, ${WHITE}n${CYAN} for none] ${NORMAL}" echo -n "${CYAN}insmod module(s)> ${NORMAL}" read MODULES case "$MODULES" in n|N) MODULES=""; ;; y|"") MODULES="$*"; ;; esac } # Try to load the given modules (full path or current directory) loadmodules(){ TYPE="$1"; shift test -n "$INTERACTIVE" && echo "6" > /proc/sys/kernel/printk for i in "$@"; do echo -n "${CRE}${BLUE}Probing ${TYPE}... ${MAGENTA}$i${NORMAL}" if test -f /modules/scsi/$i && insmod -f /modules/scsi/$i >/dev/null 2>&1 then echo "${CRE} ${GREEN}Found ${TYPE} device(s) handled by ${MAGENTA}$i${GREEN}.${NORMAL}" case "$TYPE" in scsi|SCSI) FOUND_SCSI="yes"; ;; esac fi done test -n "$INTERACTIVE" && echo "0" > /proc/sys/kernel/printk echo -n "${CRE}" } # Check for SCSI, use modules on bootfloppy first if test -n "$INTERACTIVE"; then # Let the user select interactively askmodules SCSI $(cd /modules/scsi; echo *.o) else # these are the autoprobe-safe modules MODULES="$SCSI_MODULES" fi test -z "$NOSCSI" && test -n "$MODULES" && loadmodules SCSI $MODULES # End of SCSI check # Check for misc modules in expert mode if test -n "$INTERACTIVE"; then another=""; answer="" while test "$answer" != "n" -a "$answer" != "N"; do echo -n "${CYAN}Do you want to load additional modules from$another floppy disk? [${WHITE}Y${CYAN}/n] ${NORMAL}" another=" another" read answer case "$answer" in n*|N*) break; ;; esac if mountmodules new; then askmodules new $(cd /modules/scsi; echo *.o) test -n "$MODULES" && loadmodules new $MODULES umountmodules current fi done fi # All interactively requested modules should be loaded now. # Check for ide-scsi supported CD-Roms et al. test -f /proc/scsi/scsi && FOUND_SCSI="yes" # Disable kernel messages again echo "0" > /proc/sys/kernel/printk # Now that the right SCSI driver is (hopefully) loaded, try to find CDROM DEVICES="/dev/hd?" test -n "$FOUND_SCSI" -a -z "$NOCD" && DEVICES="/dev/scd? /dev/scd?? $DEVICES" # New: Also try parallel port CD-Roms [for Mike]. DEVICES="$DEVICES /dev/pcd?" # New: also check HD partitions for a MORPHIX/MORPHIX image test -n "$FOUND_SCSI" && DEVICES="$DEVICES /dev/sd?[1-9] /dev/sd?[1-9][0-9]" DEVICES="$DEVICES /dev/hd?[1-9] /dev/hd?[1-9][0-9]" for i in $DEVICES do echo -n "${CRE}${BLUE}Looking for CDROM in: ${MAGENTA}$i${NORMAL} " if mountit $i /cdrom "-o ro" >/dev/null 2>&1 then if test -d /cdrom/base then echo -n "${CRE} ${GREEN}Accessing MORPHIX CDROM at ${MAGENTA}$i${GREEN}...${NORMAL}" FOUND_MORPHIX="$i" break fi umount /cdrom fi done # Harddisk-installed script part version has been removed # (MORPHIX can be booted directly from HD now). if test -n "$FOUND_MORPHIX" -a -f /cdrom/base/morphix; then # DEBUG # echo "6" > /proc/sys/kernel/printk insmod -f /modules/cloop.o file=/cdrom/base/morphix mountit /dev/cloop /MorphixCD "-o ro" || FOUND_MORPHIX="" fi # COPYTORAM copied (ironic, isn't it?) from Fabian's linuxrc.rampatch 2003-07-26 COPYTOHD="" COPYTO="" COPYTORAM="" case "$CMDLINE" in *toram*) COPYTO="yes"; COPYTORAM="yes"; ;; esac case "$CMDLINE" in *tohd=*) COPYTO="yes"; COPYTOHD="yes"; ;; esac # Copy the whole cdrom to ram ? if test -n "$COPYTO"; then # Pre-test if everything succeeded. if test -n "$FOUND_MORPHIX" then # copy library cache cat /MorphixCD/etc/ld.so.cache > /etc/ld.so.cache echo "" echo "Copying /cdrom to RamDisk/Harddisk, please be patient..." # Hey, we could use some fancy dialog skript here :-)) /bin/mkdir /cdrom2 if [ -n "$COPYTORAM" ] then /bin/mount -t tmpfs -o size=800M /dev/shm /cdrom2 /bin/cp -a /cdrom/* /cdrom2 # Copy everything to /cdrom2; yes we need more things then only the KNOPPIX/Morphix image, we don't want to produce problems we hadn't before, do we ? (note from Alex: this also copies any modules on the cdrom. Gotta love this patch :) else COPYTOHD=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/tohd=/s/.*=//p' | /usr/bin/tail -1) echo -n "${CRE} ${GREEN}Copying Morphix CDROM to ${MAGENTA}/dev/$COPYTOHD${GREEN}... Please be patient. ${NORMAL}" if mountit /dev/$COPYTOHD /cdrom2 >/dev/null 2>&1 then /bin/cp -a /cdrom/* /cdrom2 #/bin/mount -o remount,ro /dev/$COPYTOHD /cdrom2 else echo "${CRE} ${RED}Copying KNOPPIX CDROM failed. /dev/$COPYTOHD is not mountable. ${NORMAL}" fi fi umount /MorphixCD # unmount it echo "6" > /proc/sys/kernel/printk # Debugging rmmod cloop # release CD echo "0" > /proc/sys/kernel/printk # Debugging umount /cdrom # unmount CD if test -f /cdrom2/base/morphix; then insmod -f /modules/cloop.o file=/cdrom2/base/morphix mountit /dev/cloop /MorphixCD "-o ro" || FOUND_MORPHIX="" # if everything else did suceeded so far, this will hopefully succeed too else FOUND_MORPHIX="" fi fi fi # Final test if everything succeeded. if test -n "$FOUND_MORPHIX" then # copy library cache cat /MorphixCD/etc/ld.so.cache > /etc/ld.so.cache echo "" # Enable kernel messages echo "6" > /proc/sys/kernel/printk # Set paths echo -n "${CRE}${BLUE}Setting paths...${NORMAL}" PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:." export PATH # Debian weirdness /bin/cp -a /MorphixCD/etc/alternatives /etc/ 2>/dev/null # From here, we should have all essential commands available. hash -r # Did we copy from ram ? if test -n "$COPYTO"; then rmdir /cdrom ln -s /cdrom2 /cdrom # make a symlink and go on to normal boot fi # Clean up / rm -rf /modules #/static # New in Kernel 2.4.x: tempfs with variable ramdisk size. # We check for available memory anyways and limit the ramdisks # to a reasonable size. FOUNDMEM="$(awk '/MemTotal/{print $2}' /proc/meminfo)" TOTALMEM="$(awk 'BEGIN{m=0};/MemFree|Cached/{m+=$2};END{print m}' /proc/meminfo)" # Be verbose echo "${CRE}${BLUE}Total memory found: ${YELLOW}${FOUNDMEM}${BLUE} kB${NORMAL}" # Now we need to use a little intuition for finding a ramdisk size # that keeps us from running out of space, but still doesn't crash the # machine due to lack of Ram # Minimum size of additional ram partitions MINSIZE=2000 # At least this much memory minus 30% should remain when home and var are full. MINLEFT=16000 # Maximum ramdisk size MAXSIZE="$(expr $TOTALMEM - $MINLEFT)" # Default ramdisk size for ramdisk RAMSIZE="$(expr $TOTALMEM / 5)" # Check for sufficient memory to mount extra ramdisk for /home + /var if test -n "$TOTALMEM" -a "$TOTALMEM" -gt "$MINLEFT"; then test -z "$RAMSIZE" && RAMSIZE=1000000 mkdir -p /ramdisk # tmpfs/varsize version, can use swap RAMSIZE=$(expr $RAMSIZE \* 4) echo -n "${CRE}${BLUE}Creating ${YELLOW}/ramdisk${BLUE} (dynamic size=${RAMSIZE}k) on ${MAGENTA}/dev/shm${BLUE}...${NORMAL}" # We need /bin/mount here for the -o size= option /bin/mount -t tmpfs -o "size=${RAMSIZE}k" /dev/shm /ramdisk && mkdir -p /ramdisk/home /ramdisk/var && ln -s /ramdisk/home /ramdisk/var / echo "${BLUE}Done.${NORMAL}" else mkdir -p /home /var fi echo -n "${CRE}${BLUE}Creating directories and symlinks on ramdisk...${NORMAL}" # Create common WRITABLE (empty) dirs mkdir -p /var/run /var/backups /var/local /var/lock/news \ /var/nis /var/preserve /var/state/misc /var/tmp /var/lib \ /var/spool/cups/tmp \ /mnt/cdrom /mnt/floppy /mnt/hd /mnt/test \ /home/morph /home/root /etc/sysconfig /etc/X11 chown morph.morph /home/morph # Create empty utmp and wtmp :> /var/run/utmp :> /var/run/wtmp # All files in here should be size zero after Morphix.clean was run cp -a /MorphixCD/var/local /MorphixCD/var/log \ /MorphixCD/var/spool /var/ 2>/dev/null cp -a /MorphixCD/var/lib/nfs /MorphixCD/var/lib/xkb /MorphixCD/var/lib/isdn \ /MorphixCD/var/lib/pcmcia \ /var/lib/ 2>/dev/null # Problematic directories in /var/lib (lots and lots of inodes) ln -s /MorphixCD/var/lib/dpkg /MorphixCD/var/lib/apt \ /MorphixCD/var/lib/scrollkeeper \ /var/lib/ 2>/dev/null # Debian-apt ln -s /MorphixCD/var/cache/apt /var/cache/ 2>/dev/null ln -s /MorphixCD/etc/skel /etc/dhcpc/resolv.conf \ /etc/ 2>/dev/null ln -s /MorphixCD/dev/* /dev/ 2>/dev/null # Index files can be HUGE, so better replace cache/man tree by links later # cp -a /MorphixCD/var/cache/man /var/cache/ 2>/dev/null # Create links from CDROM for UNWRITABLE (remaining) files cp -aus /MorphixCD/var/* /var/ 2>/dev/null cp -aus /MorphixCD/etc/* /etc/ 2>/dev/null # Make SURE that these are files, not links! rm -rf /etc/passwd /etc/shadow /etc/group \ /etc/ppp /etc/isdn /etc/ssh /etc/ioctl.save \ /etc/inittab /etc/network /etc/sudoers \ /etc/init /etc/localtime /etc/dhcpc /etc/pnm2ppa.conf 2>/dev/null cp -a /MorphixCD/etc/passwd /MorphixCD/etc/shadow /MorphixCD/etc/group \ /MorphixCD/etc/ppp /MorphixCD/etc/isdn /MorphixCD/etc/ssh \ /MorphixCD/etc/inittab /MorphixCD/etc/network /MorphixCD/etc/sudoers \ /MorphixCD/sbin/init /MorphixCD/etc/dhcpc /etc/ 2>/dev/null # Extremely important, init crashes on shutdown if this is only a link :> /etc/ioctl.save :> /etc/pnm2ppa.conf # Diet libc bug workaround cp -f /MorphixCD/etc/localtime /etc/localtime echo "${BLUE}Done.${NORMAL}" # Now tell kernel where the real modprobe lives echo "/sbin/modprobe" > /proc/sys/kernel/modprobe # Change root device from /dev/fd0 to /dev/ram0 echo "0x100" > /proc/sys/kernel/real-root-dev # Give control to the init process. echo "${CRE}${BLUE}Starting init process.${NORMAL}" rm -f /linuxrc exit 0 else echo "${CRE}${RED}Can't find Morphix filesystem, sorry${NORMAL}" echo "${RED}Dropping you to a (very limited) shell${NORMAL}" echo "${RED}Make sure you have a Morphix Base image on your CD-ROM" echo "${RED}Press reset button to quit.${NORMAL}" echo "" echo "Additional builtin commands avaliable:" echo " cat mount umount" echo " insmod rmmod lsmod" echo "" PS1="morphix# " export PS1 echo "6" > /proc/sys/kernel/printk # Allow signals trap 1 2 3 15 exec /static/ash fi